package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Complain;
import com.ruoyi.system.service.IComplainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-03-03
 */
@RestController
@RequestMapping("/system/complain")
public class ComplainController extends BaseController
{
    @Autowired
    private IComplainService complainService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:complain:list')")
    @GetMapping("/list")
    public TableDataInfo list(Complain complain)
    {
        startPage();
        return getDataTable(complainService.selectComplainList(complain));
    }


    @GetMapping("/complainList")
    public TableDataInfo complainList()
    {
        return getDataTable(complainService.complainList());
    }
/*未回复*/
    @GetMapping("/noReplyComplain")
    public TableDataInfo noReplyComplain()
    {
        return getDataTable(complainService.noReplyComplain());
    }
/*匿名or未匿名*/
    @GetMapping("/getAnonymous")
    public TableDataInfo getAnonymous()
    {
        startPage();
        return getDataTable(complainService.getAnonymous());
    }
    @GetMapping("/getNoAnonymous")
    public TableDataInfo getNoAnonymous()
    {
        startPage();
        return getDataTable(complainService.getNoAnonymous());
    }
    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:complain:export')")
    @Log(title = "投诉受理导出Excel", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Complain complain)
    {
        List<Complain> list = complainService.selectComplainList(complain);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getAnonymous().equals("1")){
                list.get(i).setCompanyName("********");
            }
        }
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        util.exportExcel(response, list, "投诉受理数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:complain:query')")
    @GetMapping(value = "/{complainId}")
    public AjaxResult getInfo(@PathVariable("complainId") Long complainId)
    {
        return success(complainService.selectComplainByComplainId(complainId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:complain:add')")
    @Log(title = "投诉受理新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complain complain)
    {
        return toAjax(complainService.insertComplain(complain));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:complain:edit')")
    @Log(title = "投诉受理修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complain complain)
    {
        return toAjax(complainService.updateComplain(complain));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:complain:remove')")
    @Log(title = "投诉受理删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complainIds}")
    public int remove(@PathVariable Long[] complainIds)
    {
        return complainService.deleteComplainByComplainIds(complainIds);
    }
}
